DOUBLE PRECISION FUNCTION contoh(x)
	IMPLICIT NONE
	double precision x
	contoh = 1/(1+x)
END

DOUBLE PRECISION function soal1(x)
	IMPLICIT NONE
	double precision x
	soal1 = exp(-x) / (1+sqrt(x)+x**2)
	!soal1 = 1/(1+x)
END

DOUBLE PRECISION function soal2(x,y)
	IMPLICIT NONE
	double precision x,y
	soal2 = (x**3)*y
END

DOUBLE PRECISION function soal2_xtetap(y)
	IMPLICIT NONE
	double precision x_tetap,y
	common /xtetap/ x_tetap
	soal2_xtetap = (x_tetap**3)*y
END

DOUBLE PRECISION function soal3(x)
	IMPLICIT NONE
	double precision x, h, c, k, p, pi
	integer T
	common /soal3area/ T
	
	h  = 6.6256*1E-27
	c  = 2.99792*1E10
	k  = 1.3805*1E-16
	pi = 3.141592653589

	if(x.eq.0) then
		soal3 = 0
	else 
		soal3= 2*(pi)*(h*(c**2)) / (x**5*(exp((h*c)/(k*x*T)))-1)
	end if
END

DOUBLE PRECISION function soal_4_rekayasa(x)
	IMPLICIT NONE
	double precision cf,pf,x, pi, theta
	common /soal_4_rekayasa_global/ pi,theta
	
	soal_4_rekayasa = 1/(1-(sin(theta/2))**2*(sin(x))**0.5)
END

DOUBLE PRECISION function soal5_rekayasa(t)
! constant T = 1
	IMPLICIT NONE
	double precision t, constant_T, pi, temp
	pi = 3.1415926535897932384626433832795
	constant_T = 1.0
	if ((t.ge.0).and.(t.le.(constant_T/2))) then
		temp = 10 * exp(t/constant_T) * sin(2*pi*t/constant_T)
		soal5_rekayasa = temp ** 2
	else if ((t.ge.(constant_T/2)).and.(t.le.constant_T)) then
		soal5_rekayasa = 0
	end if
END


DOUBLE PRECISION function contoh_dif(x,y)
	IMPLICIT NONE
	double precision x, y
	contoh_dif = x + y
END

DOUBLE PRECISION function soal1_dif(x,y)
	IMPLICIT NONE
	double precision x, y
	soal1_dif = x**3 + y**2
END

DOUBLE PRECISION function soal_2_dif_dy(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	soal_2_dif_dy = -0.5 * y
END

DOUBLE PRECISION function soal_2_dif_dz(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	soal_2_dif_dz = 4 -0.3 * z - 0.1 * y
END

DOUBLE PRECISION function soal_1_dif_rekayasa_dy(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	soal_1_dif_rekayasa_dy = z
END

DOUBLE PRECISION function soal_1_dif_rekayasa_dz(x,y,z)
	IMPLICIT NONE
	double precision x,y,z,e
	common /soal_1_dif_rekayasa_global/ e
	
	soal_1_dif_rekayasa_dz = e*y**2 - y
END

DOUBLE PRECISION function soal_2_rekayasa(x)
	IMPLICIT NONE
	double precision cf,pf,x
	common /soal_2_rekayasa_global/ cf,pf
	
	soal_2_rekayasa = (cf - 1) / pf
END

DOUBLE PRECISION function soal2Rdy(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	soal2Rdy = z
	!soal2Rdy = -0.5*y
	
END

DOUBLE PRECISION function soal2Rdz(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	! cek nilai x mendekati 0, z_soal2_rekayasa_dif mendekati 0 juga
	if (x.eq.0) then
		soal2Rdz = -1*((0.1*(y**2))**1.5)/3
	else
		soal2Rdz = (-2*z/x)-((0.1*y**2)**1.5)
	end if
	!soal2Rdz = 4-0.3*z-0.1*y
	
END

DOUBLE PRECISION function soal3Rdy(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	soal3Rdy = z
end

DOUBLE PRECISION function soal3Rdz(x,y,z)
	IMPLICIT NONE
	double precision x,y,z,R,L,C
	R = 4.7
	L = 0.05
	C = 0.001
	soal3Rdz = -1*((R*z)+(y/C))/L
end

DOUBLE PRECISION function soal_4_dif_rekayasa_dy(x)
	IMPLICIT NONE
	double precision x,y,z
	
	soal_4_dif_rekayasa_dy = 0.02 * x - 0.00004 * x**2

END
